package com.tzy.dishes.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tzy.common.constant.WebResult;
import com.tzy.common.constant.WebResultMsgCode;
import com.tzy.common.entity.DishesType;
import com.tzy.dishes.service.DishesTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
 * <p>
 * 菜品分类表 前端控制器
 * </p>
 * @author 谭同学
 * @since 2022-03-11
 */
@Slf4j
@RestController
@RequestMapping("/dishes/type")
public class DishesTypeController {
    @Resource
    private DishesTypeService dishesTypeService;
    @GetMapping("/page")
    public WebResult getDishesTypePage(@RequestParam(defaultValue = "1") Integer pageNum){
        Page<DishesType> pageInfo = new Page<>(pageNum, 10);
//        QueryWrapper<DishesType> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("is_deleted",0);
        Page<DishesType> page = dishesTypeService.getPage(pageInfo, null);
        return new WebResult(WebResultMsgCode.SUCCESS,page);
    }

    @PostMapping("/insert")
    public WebResult getDishesTypeList(String typeOfDishes){
        DishesType dishesType = new DishesType();
        dishesType.setTypeOfDishes(typeOfDishes);
        boolean save = dishesTypeService.save(dishesType);
        return new WebResult(WebResultMsgCode.SUCCESS,save);
    }
    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public WebResult logicalDeletion(int id){
        log.info("id="+ id);
        DishesType dishesType = new DishesType();
        dishesType.setId(id);
        dishesType.setIsDeleted(1);
        boolean updateById = dishesTypeService.updateById(dishesType);
        return new WebResult(WebResultMsgCode.SUCCESS,updateById);
    }

    /**
     * 修改状态
     * @param id
     * @return
     */
    @PutMapping("/update/status")
    public WebResult updateStatus(int id){
        log.info("id="+ id);
        DishesType dishesType = new DishesType();
        dishesType.setId(id);
        dishesType.setIsDeleted(0);
        boolean updateById = dishesTypeService.updateById(dishesType);
        return new WebResult(WebResultMsgCode.SUCCESS,updateById);
    }
}
